//> using scala "3.3.1"
//> using lib "com.lihaoyi::cask:0.9.2"
//> using lib "com.lihaoyi::scalatags:0.8.2"
{{>licenseInfo}}

// this file was generated from app.mustache
package {{packageName}}

{{#imports}}import {{import}}
{{/imports}}
import _root_.{{modelPackage}}.*
import _root_.{{apiPackage}}.*

/**
 * This class was created with the intention of being extended by some runnable object,
 * passing in the custom business logic services
 */
class BaseApp({{#operations}}
    override val app{{classname}}Service : {{classname}}Service = {{classname}}Service(),
{{/operations}}
    override val port : Int = sys.env.get("PORT").map(_.toInt).getOrElse(8080)) extends cask.MainRoutes with AppRoutes {

    /** routes for the UI
     * Subclasses can override to turn this off
     */
    def openApiRoute: Option[cask.Routes] = Option(OpenApiRoutes(port))

    override def allRoutes = appRoutes ++ openApiRoute

    {{^operations}}
        // no operations!
    {{/operations}}

    override def host: String = "0.0.0.0"

    def start() = locally {
        initialize()
        println(box(s""" 🚀 browse to localhost:$port 🚀
        |      host : $host
        |      port : $port
        |   verbose : $verbose
        | debugMode : $debugMode
        |""".stripMargin))

        // if java.awt.Desktop.isDesktopSupported then {
        //    java.awt.Desktop.getDesktop.browse(new java.net.URI(s"http://localhost:${port}"))
        // }
    }
}
